<template>
  <div>
    <search @search="handleSearchByKeyword" @add="handleOpenDialog"/>
    <template>
      <ms-table :table-props="tableProps" :data-api="dataUrl" ref="dataTable" size="small">
        <el-table-column label="操作" slot="tool">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleOpenDialog(scope.row.id)">编辑</el-button>
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </ms-table>
    </template>
    <info :title="title" ref="infoForm" :dialog-visible="dialog1" :form-id="formId" @dataFresh="handleCanleDialog" @close="handleCanleDialog" />
  </div>
</template>

<script>
import { deleteDict } from '@/api/sys/dict'
import { MsTable } from '@/common/table'
import Search from './Search'
import Info from './Info'
import common from '@/mixins/common'
export default {
  components: {
    MsTable,
    Search,
    Info
  },
  mixins: [common],
  props: ['dictType'],
  watch: {
    dictType: {
      immediate: true,
      handler(dictType) {
        this.searchForm.dictType = dictType
        this.handleFreshTable()
      }
    }
  },
  data() {
    return {
      tableProps: [
        { index: 'dictValue', label: '字典值' },
        { index: 'code', label: '对应码' }
      ],
      dataUrl: '/sys/dict/list',
      mainTitle: '字典子类型'
    }
  },
  methods: {
    handleDelete(id) {
      deleteDict(id)
      this.handleFreshTable()
    }
  }
}
</script>
